

<%@page contentType="text/html" pageEncoding="UTF-8" import="Modelo.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%

        Factor fac= new Factor();
        String nombre="";
        String desc="";

        if(request.getParameter("nombre")!=null && !request.getParameter("nombre").equals("")){
        nombre = (String) request.getParameter("nombre");

        }
        if(request.getParameter("descripcion")!=null && !request.getParameter("descripcion").equals("")){
        
        desc = (String) request.getParameter("descripcion");
        }
        if(nombre.equals("") || desc.equals("") ){
        response.sendRedirect(request.getContextPath()+"/factor/crear.jsp?error=1");
        }



        fac.setNombre(nombre);
        fac.setDescripcion(desc);
        //new Factor().agregarFactor(fac);

        Long idfact=new Factor().agregarFactor(fac);
        Factor facto= new Factor().findFactor(idfact);
        int j=1;
         while((String)request.getParameter("caracteristica"+j)!=null){
                String idcaracteristica =(String)request.getParameter("caracteristica"+j);
                 j++;


                Caracteristica ca = new Caracteristica();
                ca = ca.findCaracteristica(Long.parseLong(idcaracteristica));
                ca.setFactor(facto);
                new Caracteristica().actualizarCaracteristica(ca);
                new Factor().asignarC(idfact,ca);


         }


        response.sendRedirect(request.getContextPath()+"/factor/mostrar.jsp");
    %>
       
    </body>
</html>
